|
ARD2
RC2
Airbag Reference Demonstrator using MPC5604P
|
00001 00017 #include "derivative.h" 00018 #include "Compile_Options.h" 00019 #include "Init_State.h" 00020 #include "SM.h" 00021 #include "SBC_AL.h" 00022 #include "Central_Accel_AL.h" 00023 #include "HAL.h" 00024 #include "Application_Globals.h" 00025 #include "MailScheduler.h" 00026 #ifdef USE_LABVIEW 00027 #include "Labview.h" 00028 #endif 00029 /* 00030 ****************************************************************************** 00031 * Constants 00032 ****************************************************************************** 00033 */ 00037 static const uint16_t cu16SMInitValidInputStates = SM_STATE_SETUP; 00038 #ifdef USE_LABVIEW 00039 static const uint8_t cau8SuccessGUIMsg01[] = "Initialization successful."; 00040 #endif 00041 /* 00042 ****************************************************************************** 00043 * Globals 00044 ****************************************************************************** 00045 */ 00046 /* 00047 ****************************************************************************** 00048 * u32fnSMInit 00049 ****************************************************************************** 00050 */ 00051 uint32_t u32fnSMInit(void) 00052 { 00053 uint32_t u32Status; 00054 00055 /* Verify that we can execute - Previous state ended correctly */ 00056 u32Status 00057 = u32fnSMValidateCurrentState((uint16_t*)&cu16SMInitValidInputStates, 1u); 00058 if(CLEAR == u32Status) 00059 { 00060 /* Here comes the real contents of the state */ 00061 LOCK_STATE_EXECUTION(); 00062 00063 (void)u8fnSBCPreSchedulerEnableWarningLamp(TRUE); 00064 00065 vfnSMInitAppGlobals(); 00066 00067 /* Pre-scheduler config for SBC, Central Accel. */ 00068 vfnSBCPreSchedulerInit(); 00069 vfnCAPreSchedulerInit(); 00070 00071 if(CLEAR == u8fnInitPostalService(TRUE)) 00072 { 00073 if(CLEAR == u8fnLaunchScheduler(TRUE)) 00074 { 00075 /* Run initial tests, finalize configuration for Central */ 00076 /* Accelerometer These go first because our CA needs */ 00077 /* some time after configuration and before requesting */ 00078 /* measurements */ 00079 if(CLEAR == u32fnCAInit()) 00080 { 00081 /* Add small delay to 1) separate SPI transfers and */ 00082 /* 2) allow extra time for the CA to take it's config */ 00083 DELAY_MSEC(1u); 00084 00085 /* Same as above for SBC */ 00086 u32Status = u32fnSBCInit(); 00087 00088 /* Give some time for sync pulses to line up */ 00089 DELAY_MSEC(1u); 00090 } 00091 else 00092 { 00093 /* Central accelerometer is not happy */ 00094 u32Status = INIT_STATE_CA_ERROR; 00095 } 00096 } 00097 else 00098 { 00099 /* Flag it as an error */ 00100 u32Status = INIT_STATE_MCU_ERROR; 00101 } 00102 } 00103 else 00104 { 00105 /* Flag it as an error */ 00106 u32Status = INIT_STATE_MCU_ERROR; 00107 } 00108 00109 SCHED_WHAT_IS_THE_TIME(gu32SMCycleStartTime); 00110 /* Unlock the state */ 00111 UNLOCK_STATE_EXECUTION(); 00112 } 00113 else 00114 { 00115 /* Leave */ 00116 } 00117 00118 /* Set the next state */ 00119 if(CLEAR == u32Status) 00120 { 00121 vfnSMWriteNextState(SM_APPLICATION_START); 00122 #ifdef USE_LABVIEW 00123 vfnDisplayGUISuccessMessage(); 00124 #endif 00125 } 00126 else 00127 { 00128 vfnSMWriteNextState(SM_STATE_ERROR); 00129 } 00130 return (u32Status); 00131 } 00132 #ifdef USE_LABVIEW 00133 /* 00134 ****************************************************************************** 00135 * vfnDisplayGUISuccessMessage 00136 ****************************************************************************** 00137 */ 00138 static void vfnDisplayGUISuccessMessage(void) 00139 { 00140 vfnLVEnable(TRUE); 00141 (void)u8fnLVWaitForTxPort(); 00142 (void)u8fnLabViewSendMSorMP((uint8_t*)&cau8SuccessGUIMsg01, sizeof(cau8SuccessGUIMsg01), 00143 LV_SEND_SERIALLY, LV_MP_MSG); 00144 vfnLVEnable(CLEAR); 00145 return; 00146 } 00147 #endif 00148 /* 00149 ****************************************************************************** 00150 * 00151 * End of file. 00152 * 00153 ****************************************************************************** 00154 */